Connection String Incorrectly Formatted [migrated]
Posted
by
Randy E
on Programmers
See other posts from Programmers
or by Randy E
Published on 2012-10-07T19:25:57Z
Indexed on
2012/10/07
21:51 UTC
Read the original article
Hit count: 266
I'm running into some issues. Every time I launch into debug mode and hit the "Create User" button, I'm getting an exception being thrown that is due to the Connection String either being in the wrong syntax or just wrong.
Using Visual Studio 2010, project is .NET 3.5 with SQL 2008 Express.
This is just a personal project that I'm testing some other things with, I know this generally isn't the recommended format but for a personal small project, I don't see the point in doing it any other way. The things I'm testing actually work :)
Data Source=.\SQLEXPRESS;AttachDbFilename=|Data Directory|ASPAppDatabase.mdf;Integrated Security=True;User Instance=True
That doesn't work.
Data Source=.\SQLEXPRESS;AttachDbFilename="|Data Directory|ASPAppDatabase.mdf";Integrated Security=True;User Instance=True
Neither does that.
Data Source=.\SQLEXPRESS;AttachDbFilename='|Data Directory|ASPAppDatabase.mdf';Integrated Security=True;User Instance=True
And again, neither does that :/
However, rather than using "|Data directory| if I use the full path to the local DB file it works just fine and no exception is thrown, and I can read and write as I need.
And just to cover all my bases, here is the button click event that creates the User.
protected void btnAddUser_Click(object sender, EventArgs e)
{
Membership.CreateUser(txtUserName.Text, txtPassword.Text);
btnLogin_Click(sender, e);
}
So, what am I missing in regards to the |Data Directory|?
Here is an example of the above not working correctly..taken directly from web.config.
<add name="ASPAppDatabaseConnection" connectionString='Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|ASPAppDatabase.mdf;Integrated Security=True;User Instance=True'/>
© Programmers or respective owner